from abc import ABC, abstractmethod
from enum import Enum

class TaskStatus(Enum):
    PENDING = "pending"
    RUNNING = "running"
    COMPLETED = "completed"
    FAILED = "failed"    

# 每一个任务类（对象）都需要实现这个接口

class TaskProtocol(ABC):
    def __init__(self,task_id,task_data):
        self.task_id = task_id
        self.task_data = task_data
        self.status = TaskStatus.PENDING
    
    @abstractmethod
    def start(self):
        self.status = TaskStatus.RUNNING

    @abstractmethod
    def complete(self,result):
        self.status = TaskStatus.COMPLETED
        self.result = result

    @abstractmethod
    def fail(self,error):
        self.status = TaskStatus.FAILED
        self.error = error
    
